package com.marvels.approve.process.consum.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.marvels.approve.process.consum.ConsumerDecisionExecuteApi;
import com.marvels.approve.process.dto.StrategyResponseDTO;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.dubbo.coreservice.service.DecisionExecuteDubboService;

@Component
public class ConsumerDecisionExecuteImpl implements ConsumerDecisionExecuteApi {

	@Autowired
	private DecisionExecuteDubboService decisionExecuteDubboService;
	
	@Override
	public StrategyResponseDTO getDecisionResult(String loanId, String productType) {
		try {
			com.dragon.loan.entity.StrategyResponse apiResult = decisionExecuteDubboService.getDecisionResult(loanId, productType);
			StrategyResponseDTO result = JSONObject.parseObject(JSONObject.toJSONString(apiResult), StrategyResponseDTO.class);
			MarvelsLogUtil.getInstance().info("ConsumerDecisionExecuteApi.getDecisionResult direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ConsumerDecisionExecuteApi.getDecisionResult error", e);
			return null;
		}
	}

}
